package com.firebird.app.fekpsl.adapter

import android.content.Context
import android.text.Html
import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.firebird.app.fekpsl.R
import com.firebird.app.fekpsl.bean.Wall
import com.firebird.app.fekpsl.utils.ImageLoader
import com.firebird.app.fekpsl.utils.TimeFriendlyUtil.friendlyTime
/**
 * Created by firebird on 2018/4/22.
 */
class HomeAdapter(private val context: Context?, datas: MutableList<Wall>)
    : BaseQuickAdapter<Wall, BaseViewHolder>(R.layout.item_home_list, datas) {
    override fun convert(holder: BaseViewHolder?, item: Wall?) {
        item ?: return
        holder ?: return
        val authorStr = if (item.is_explicit==1) item.nice_name else item.real_name
        holder.setText(R.id.tv_wall_message, Html.fromHtml(item.message))
                .setText(R.id.tv_wall_author, authorStr)
                .addOnClickListener(R.id.iv_wall_avatar)
        val friendlyTime=friendlyTime(item.create_time)
        holder.setText(R.id.tv_wall_date, friendlyTime)
        val examName = item.name
        holder.setText(R.id.tv_wall_exam_name, examName)
        if (item.avatar_text.isNotEmpty()) {
            holder.getView<ImageView>(R.id.iv_wall_avatar)
                    .visibility = View.VISIBLE
            context?.let {
                ImageLoader.load(it, item.avatar_text, holder.getView(R.id.iv_wall_avatar))
            }
        } else {
            context?.let {
                holder.getView<ImageView>(R.id.iv_wall_avatar)
                        .setImageDrawable(it.resources.getDrawable(R.drawable.icon_default_user))
            }
        }
    }
}
